package controller;

import java.sql.Timestamp;
import java.util.List;

import javax.faces.context.FacesContext;
import javax.servlet.http.HttpSession;

import model.Mesa;
import model.Reservation;


public class ReserveBean {
	private Timestamp fecha;
	private String errors;
	private int mesaId;
	
	public List<Mesa> getMesasDisponibles(){
		Mesa m = new Mesa();
		return m.getMesas();
	}
	
	public String reserve(){
		FacesContext context = FacesContext.getCurrentInstance();
		HttpSession session = (HttpSession) context.getExternalContext().getSession(false);				
		String username = (String) session.getAttribute("user");
		
		Reservation r = new Reservation();
		
		if (r.reserve(this.fecha, username))
			return "success";
		errors = "Error en la reserva.";
		return null;
	}

	public Timestamp getFecha() {
		return fecha;
	}

	public void setFecha(Timestamp fecha) {
		this.fecha = fecha;
	}

	public String getErrors() {
		return errors;
	}

	public void setErrors(String errors) {
		this.errors = errors;
	}

	public int getMesaId() {
		return mesaId;
	}

	public void setMesaId(int mesaId) {
		this.mesaId = mesaId;
	}
	
}
